
" 判断vim 环境
function! Cond(cond, ...)
  let opts = get(a:000, 0, {})
  return a:cond ? opts : extend(opts, { 'on': [], 'for': [] })
endfunction

"  -------------------------------------- 插件管理 vim-plug start-----------------------------------

call plug#begin('C:\Users\admin\AppData\Local\nvim\autoload\plugins')

Plug 'easymotion/vim-easymotion', Cond(!exists('g:vscode')) " 使用普通的easymotion
Plug 'asvetliakov/vim-easymotion', Cond(exists('g:vscode'), { 'as': 'vsc-easymotion' }) " 使 vscodl easymotion 
Plug 'yonchu/accelerated-smooth-scroll'
call plug#end()

"  -------------------------------------- 插件管理 vim-plug end -----------------------------------


"  -------------------------------------- 插件配置 start -----------------------------------

"  -------------------------------------- 插件配置 end -----------------------------------

"  -------------------------------------- 基本功能设置  start -----------------------------------

set ic " 搜索忽略大小写

function! s:openVSCodeCommandsInVisualMode()
    normal! gv
    let visualmode = visualmode()
    if visualmode == "V"
        let startLine = line("v")
        let endLine = line(".")
        call VSCodeNotifyRange("workbench.action.showCommands", startLine, endLine, 1)
    else
        let startPos = getpos("v")
        let endPos = getpos(".")
        call VSCodeNotifyRangePos("workbench.action.showCommands", startPos[1], endPos[1], startPos[2], endPos[2], 1)
    endif
endfunction

" 实现自动切换输入法
if exists('g:vscode')
    autocmd InsertLeave * :silent :!D:\\tools\\im-select.exe 1033
    autocmd InsertEnter * :silent :!D:\\tools\\im-select.exe 2052
else
endif

"  -------------------------------------- 基本功能设置  end -----------------------------------

"  -------------------------------------- 键位配置  start -----------------------------------
" 配置 leader 键为空格
let mapleader=" "

" workaround for calling command picker in visual mode
xnoremap <silent> <C-P> :<C-u>call <SID>openVSCodeCommandsInVisualMode()<CR>
xnoremap <silent> <C-Insert> call <SID>openVSCodeCommandsInVisualMode()<CR>

noremap <C-a> ggVG
if exists('g:vscode')
    " 注释命令
    xmap gc  <Plug>VSCodeCommentary
    nmap gc  <Plug>VSCodeCommentary
    omap gc  <Plug>VSCodeCommentary
    nmap gcc <Plug>VSCodeCommentaryLine
    
    " 配置ctrl + a
else
    " ordinary neovim
endif

"  -------------------------------------- 键位配置  end -----------------------------------


